<?php
/**
 * 个人中心管理类
 * comfiger
 * 2018-6-20
 **/
namespace Mama\Model;
use Think\Model;
class UcenterModel extends Model{
	//定义表名称
	protected $tableName = 'member_invoice';
	
	/**
	 * 根据用户ID获取发票列表
	 **/
	public function getInvoiceListByUserId($userid){
		return $this->where(array('userid' => $userid))->order('is_default desc,invoice_id asc')->select();
	}
	
	/**
	 * 获取详情
	 **/
	public function getInvoiceInfoByInvoiceId($invoice_id){
		return $this->where(array('invoice_id' => $invoice_id))->find();
	}
	
	/**
	 * 添加发票
	 **/
	public function addInvoiceInfo($data){
		return $this->data($data)->add();
	}
	
	/**
	 * 编辑发票信息
	 **/
	public function editInvoiceInfoByInvoiceId($invoice_id, $data){
		return $this->where(array(
			'invoice_id' => $invoice_id
		))->setField($data);
	}
	
	/**
	 * 设置默认
	 **/
	public function editInvoiceDefaultByInvoiceId($invoice_id, $userid){
		$this->where(array('userid' => $userid))->setField(array(
			'is_default' => 0
		));
		
		return $this->where(array(
			'invoice_id' => $invoice_id
		))->setField(array(
			'is_default' => 1
		));
	}
	//情况默认
	public function clearInvoiceDefault($userid){
		return $this->where(array('userid' => $userid))->setField(array(
			'is_default' => 0
		));
	}
}